﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectHandlers
{
    public class GetClosedProjectList
    {
        private readonly ProjectRepository _projectRepository;

        public GetClosedProjectList()
        {
            _projectRepository = new ProjectRepository();
        }

        public GetClosedProjectList(ProjectRepository projectRepository)
        {
            _projectRepository = projectRepository;
        }

        public virtual IEnumerable<ProjectModel> Execute()
        {
            IEnumerable<PROJECT> projectData = null;

            //get from db
            try
            {
                projectData = _projectRepository.GetClosedProjects();
            }
            catch(Exception ex)
            {
                LogService.Service.Debug(ex);
            }

            var projectModel = from p in projectData
                               select new ProjectModel(p);

            return projectModel;
        }
    }
}
